package com.dq.repository.user;


import com.dq.domain.org.Org;
import com.dq.domain.org.OrgCustomerLevel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Author luchangtong
 * @Date 2019/12/16 15:31
 */
@Repository
public interface OrgCustomerLevelRepository extends JpaRepository<OrgCustomerLevel,Long> {
    List<OrgCustomerLevel> findBySysDeptAndDeletedFalse(Org sysDept);

    OrgCustomerLevel findByMinAmountLessThanEqualAndMaxAmountGreaterThanEqualAndDeletedFalse(BigDecimal sum,BigDecimal sum2);

    @Query(value = "SELECT m.* FROM org_customer_level m " +
            "where m.deleted = false " +
            "and if(:orgId is not null, m.sys_dept_id = :orgId, 1=1) " +
            " group by m.leven_name "
            , nativeQuery = true)
    List<OrgCustomerLevel> findBySysDeptAndDeletedFalseGroupByLevenName(Long orgId);
}
